package com.lz.football.module.friend
{
	import com.common.utils.Reflection;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.FriendEvent;
	import com.liangzhong.model.AppData;
	
	import common.BaseView.BaseView;
	
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import lz.controls.Alert;

	/**
	 *输入名称申请添加好友  
	 * @author Administrator
	 * 
	 */	
	public class AddFriendView extends BaseView
	{
		/**
		 *输入 文本 
		 */
		private var inputText:TextField;
		/**
		 *确定按钮 
		 */
		private var sureBtn:SimpleButton;
		/**
		 *取消按钮 
		 */
		private var cancelBtn:SimpleButton;
		public function AddFriendView()
		{
			super();
		}
		override public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.football.module.friend.addFriendView");
			this.addChild(symbolSkin);
			inputText = symbolSkin.inputText;
			sureBtn = symbolSkin.sureBtn;
			cancelBtn = symbolSkin.cancelBtn;
			setCloseBtn(symbolSkin.closeBtn);
			_windowBg = symbolSkin.windowBg;
			isDrag = true;
			_viewWidth = this.width;
			_viewHeight = this.height;
			inputText.maxChars = 10;
			inputText.text = "请输入名称";
			onResizeHandler();
			addEvtListener();
		}
		override public function addEvtListener():void
		{
			super.addEvtListener();
			cancelBtn.addEventListener(MouseEvent.CLICK,onCloseHandler);
			inputText.addEventListener(MouseEvent.CLICK,onInputHandler);
			this.addEventListener(Event.ADDED_TO_STAGE,onAddstageHandler);
			sureBtn.addEventListener(MouseEvent.CLICK,onSureHandler);
		}
		
		/**
		 *确定 
		 * @param event
		 * 
		 */
		protected function onSureHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			
			if(inputText.text == "")
			{
				Alert.showErrorTip("请输入名称");
				return;
			}
			sureBtn.removeEventListener(MouseEvent.CLICK,onSureHandler);
			AppEventDispatcher.getInstance().dispatchEvent(new FriendEvent(FriendEvent.NAME_INVITE,{playerName:inputText.text}));
		}
		
		/**
		 *添加到舞台 
		 * @param event
		 * 
		 */
		protected function onAddstageHandler(event:Event):void
		{
			// TODO Auto-generated method stub
			inputText.text = "请输入名称";
		}
		
		protected function onInputHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			if(inputText.text == "请输入名称")
				inputText.text = "";
			this.stage.focus = inputText;
		}
		 /**
		*名称邀请返回 
		* @param $obj
		* 
		*/
		public function nameInvite($obj:Object):void
		{
			sureBtn.addEventListener(MouseEvent.CLICK,onSureHandler);
		}
	}
}